package io.renren.modules.generator.service.impl;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import io.renren.datasource.annotation.DataSource;
import io.renren.modules.generator.entity.LabelEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.generator.dao.LabelDao;
import io.renren.modules.generator.entity.LabelEntity;
import io.renren.modules.generator.service.LabelService;


@Service("labelService")
public class LabelServiceImpl extends ServiceImpl<LabelDao, LabelEntity> implements LabelService {

    @Autowired
    LabelDao labelDao;
    @Override
    @DataSource("slave2")
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<LabelEntity> page = this.page(
                new Query<LabelEntity>().getPage(params),
                new QueryWrapper<LabelEntity>()
        );

        return new PageUtils(page);
    }

    @DataSource("slave2")
    @Override
    public LabelEntity getById(Integer id) {
        LabelEntity labelEntity = labelDao.selectById(id);
        return labelEntity;
    }

    @Override
    @DataSource("slave2")
    public boolean save(LabelEntity entity) {
        entity.setCreationTime(new Date());
        entity.setUpdateTime(new Date());
        return SqlHelper.retBool(labelDao.insert(entity));
    }


    @DataSource("slave2")
    @Override
    public boolean updateById(LabelEntity label) {
        label.setUpdateTime(new Date());
        return SqlHelper.retBool(labelDao.updateById(label));
    }

    @DataSource("slave2")
    @Override
    public boolean removeByIds(List idList) {
        return CollectionUtils.isEmpty(idList) ? false : SqlHelper.retBool(labelDao.deleteBatchIds(idList));
    }

}